package com.tao.controller.webpageController;

import com.tao.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
@RequestMapping("/webPage/shop")
public class ShopController {
    @Autowired
    RedisTemplate redisTemplate;
    public static final String key = "shop_status";
    @GetMapping("/status")
    public Result getStatus(){
        log.info("查询店铺状态");
        ValueOperations valueOperations = redisTemplate.opsForValue();
        return Result.success((Integer) valueOperations.get(key));
    }

    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        log.info("营业状态即将改为:{}",status==1?"营业中":"已下班");
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(key,status);
        return Result.success();
    }
}
